Next:
Smart pointer
, Previous:
STL sequence container
, Up:
Index
STL container adapter
STL container adapter
활용도가 높은 자료구조를 제공한다.
기존의 C언어를 이용하면서 구현하기 어려웠던 다양한 자료구조를 손쉽게 이용할 수 있다.
- Stack
- Queue
- Priority Queue
C++ STACK STL
추가: push(element)
삭제: pop()
조회: top()
검사: empty() / size()
#include <iostream>
#include <stack>
using
namespace
std
;
int
main
(
void
)
{
stack
<
int
>
s
;
s
.
push
(
7
)
;
s
.
push
(
5
)
;
s
.
push
(
4
)
;
s
.
pop
(
)
;
s
.
push
(
6
)
;
s
.
pop
(
)
;
while
(
!
s
.
empty
(
))
{
cout
<<
s
.
top
(
)
<<
' '
;
s
.
pop
(
)
;
}
system
(
"pause"
)
;
return
0
;
}
C++ QUEUE STL
추가: push(element)
삭제: pop()
조회: front() / back()
검사: empty() / size()
#include <iostream>
#include <queue>
using
namespace
std
;
int
main
(
void
)
{
queue
<
int
>
q
;
q
.
push
(
7
)
;
q
.
push
(
5
)
;
q
.
push
(
4
)
;
q
.
pop
(
)
;
q
.
push
(
6
)
;
q
.
pop
(
)
;
while
(
!
q
.
empty
(
))
{
cout
<<
q
.
front
(
)
<<
' '
;
q
.
pop
(
)
;
}
system
(
"pause"
)
;
return
0
;
}
C++ PRIORITY QUEUE
queue library에 포함되어 있음
#include <iostream>
#include <queue>
using
namespace
std
;
int
main
(
void
)
{
int
n
,
x
;
cin
>>
n
;
priority_queue
<
int
>
pq
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
cin
>>
x
;
pq
.
push
(
x
)
;
}
while
(
!
pq
.
empty
(
))
{
cout
<<
pq
.
top
(
)
<<
' '
;
pq
.
pop
(
)
;
}
system
(
"pause"
)
;
return
0
;
}